home *** CD-ROM | disk | FTP | other *** search
- /*
- File: LibraryManagerUtilities.h
-
- Contains: Interfaces file for LibraryManager utilities
-
- Copyright: © 1991-1992 by Apple Computer, Inc., all rights reserved.
-
- */
-
-
- #ifndef __LIBRARYMANAGERUTILITIES__
- #define __LIBRARYMANAGERUTILITIES__
-
- #ifndef __LIBRARYMANAGER__
- #include <LibraryManager.h>
- #endif
-
- /**********************************************************************
- ** Typedefs
- ***********************************************************************/
-
- #ifndef MACOS
- typedef Ptr* Handle;
- typedef unsigned long ResType;
- typedef const unsigned char* ConstStr255Param;
- #endif
-
- /**********************************************************************
- ** Routines for loading and unloading the LibraryManager.
- **
- ** UnloadLibraryManager and LoadLibraryManager can be bad for your health!
- ** They should only be used for testing purposes.
- ***********************************************************************/
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- Boolean IsLibraryManagerLoaded();
- Boolean LoadLibraryManager(); // returns true if successful or already loaded
- void UnloadLibraryManager();
-
- /**********************************************************************
- ** GetSLMVersion
- **
- ** Returns the version of the installed LibraryManager in the 'vers'
- ** resource format (the first 4 bytes only). Returns 0 if the
- ** LibraryManager is not installed.
- ***********************************************************************/
-
- unsigned long GetSLMVersion();
-
- /**********************************************************************
- ** RegisterInspector
- **
- ** Should only be used by Inspector application.
- ***********************************************************************/
-
- void RegisterInspector(void*);
-
- /**********************************************************************
- ** Trace
- **
- ** Used to send output to the Inspector's Trace Window.
- ***********************************************************************/
-
- void Trace(const char *formatStr, ...);
-
- /**********************************************************************
- ** SLMsprintf
- **
- ** The SLMsprintf routine in stdclib.o won't work with LibraryManager libraries.
- ** Use the one in LibraryManager.o instead.
- ***********************************************************************/
-
- int SLMsprintf(char *outString, const char *argp, ...);
-
- /**********************************************************************
- ** Utility functions for getting high and low bytes and words
- ***********************************************************************/
-
- #ifdef __cplusplus
-
- inline unsigned short HighWord(unsigned long l)
- {
- return (unsigned short)((l >> 16) & 0xffff);
- }
-
- inline unsigned short LowWord(unsigned long l)
- {
- return (unsigned short)(l & 0xffff);
- }
-
- inline unsigned char HighByte(unsigned short l)
- {
- return (unsigned char)((l >> 8) & 0xff);
- }
-
- inline unsigned char LowByte(unsigned short l)
- {
- return (unsigned char)(l & 0xff);
- }
-
- #else
-
- #define HighWord(x) ((unsigned short)(((x) >> 16) & 0xffff))
- #define LowWord(x) ((unsigned short)((x) & 0xffff))
- #define HighByte(x) ((unsigned char)(((x) >> 8) & 0xff))
- #define LowByte(x) ((unsigned char)((x) & 0xff))
-
- #endif
-
- /*******************************************************************************
- ** Atomic Bit functions
- **
- ** These functions atomically set and clear bits, and return what value the
- ** bit previously had
- ********************************************************************************/
-
- Boolean SetBit(void* mem, size_t bitno);
- Boolean ClrBit(void* mem, size_t bitno);
- Boolean TstBit(const void* mem, size_t bitno);
-
- /**********************************************************************
- ** Memory Functions
- **
- ** memcpy and memmove are declared in String.h, but we also declare them
- ** here just to let you know that the LibraryManager provides its own
- ** implementationin LibraryManager.o.
- ***********************************************************************/
-
- void ZeroMem(void* destPtr, size_t byteCount);
- void* memcpy(void* destPtr, void* srcPtr, size_t byteCount);
- void* memmove(void* destPtr, void* srcPtr, size_t byteCount);
-
- /*******************************************************************************
- ** EnterSystemMode/LeaveSystemMode
- **
- ** These functions should bracket calls that open files or get memory that needs
- ** to hang around after an application quits
- ********************************************************************************/
-
- void* EnterSystemMode();
- void LeaveSystemMode(void*);
-
- /*******************************************************************************
- ** Exception Handling
- **
- ** This stuff is only needed by the exception handling macros. Don't use directly!
- ********************************************************************************/
-
- #ifdef __cplusplus
- class TException;
- #else
- typedef void TException;
- #endif
-
- void PushExceptionHandler(TException*);
- TException* PopExceptionHandler();
-
-
- /*******************************************************************************
- ** EnterInterrupt/LeaveInterrupt
- **
- ** These functions should be called when you are in an interrupt service routine
- ** or a deferred task and you want to do something that will cause LibraryManager
- ** code to be executed such as allocating pool memory or newing an object. The
- ** LibraryManager needs to know that it is at interrupt time so it doesn't do
- ** anything stupid like try to allocate memory or load library code. This doesn't
- ** mean that all LibraryManager calls are safe at interrupt time, just that the
- ** ones that claim to be safe will only be safe if you do an EnterInterrupt call
- ** first.
- **
- ** You don't need to use these routines when your interrupt service routine is
- ** scheduling an operation on a TInterruptScheduler, when the operation gets
- ** executed at deferred task time, or when a TTimeScheduler operation gets
- ** executed. In the former case the LibraryManager is smart enough to realize
- ** that you are at interrupt time and in the later two cases the
- ** LibraryManager does an EnterInterrupt before calling your operation and a
- ** LeaveInterrupt when your operation returns.
- ********************************************************************************/
-
- void EnterInterrupt();
- void LeaveInterrupt();
-
- /*******************************************************************************
- ** AtInterruptLevel
- **
- ** This function returns true if we are currently executing at non-system-task
- ** time.
- ********************************************************************************/
-
- Boolean AtInterruptLevel();
-
- /*******************************************************************************
- ** InInterruptScheduler
- **
- ** This function returns true if we are currently running an interrupt scheduler
- ********************************************************************************/
-
- Boolean InInterruptScheduler();
-
- /**********************************************************************
- ** GlobalWorld routines
- **
- ** InitGlobalWorld will create and initialize the global world for
- ** standalone code on the MacOS such as INITs and CDEVs. It also does
- ** a SetCurrentGlobalWorld. FreeGlobalWorld will free the memory used
- ** by the global world created by InitGlobalWorld.
- **
- ** SetCurrentGlobalWorld and GetCurrentGlobalWorld used for getting and
- ** setting A5 on the MacOS.
- **
- ** GetGlobalWorld is used to get the global world pointer for a Library.
- ** OpenGlobalWorld will make the library's global world the current global
- ** world. It's the same as calling SetCurrentGlobalWorld(GetGlobalWorld()).
- ** CloseGlobalWorld is used to revert back to the global world that was
- ** current before calling OpenGlobalWorld. It's the same as calling
- ** SetCurrentGlobalWorld(oldWorld) except that it doesn't return a
- ** global world.
- **
- ** Since libraries are always compiled with model far, it's
- ** not necessary to do an OpenGlobalWorld before accessing globals or
- ** making intersegment calls. Their only purpose is to make the library
- ** the current "Client" since the client is determined by the current
- ** value of A5 on the MacOS.
- **
- ** ONLY LIBRARIES AND MODEL FAR CLIENTS SHOULD CALL Get/Open/CloseGlobalWorld.
- ***********************************************************************/
-
- typedef void* GlobalWorld;
-
- #ifndef kInvalidWorld
- #define kInvalidWorld ((GlobalWorld)0)
- #endif
-
- #pragma parameter __D0 SetCurrentGlobalWorld(__A0)
- GlobalWorld SetCurrentGlobalWorld(GlobalWorld newWorld)
- = {0x200D, /* move.l A5,D0 */
- 0x2A48}; /* move.l A0,A5 */
-
- GlobalWorld GetCurrentGlobalWorld()
- = {0x200D}; /* move.l A5,D0 */
-
- #ifdef __cplusplus
- inline GlobalWorld GetGlobalWorld() {return __gLibraryManager->GetGlobalWorld();}
- inline GlobalWorld OpenGlobalWorld() {return SetCurrentGlobalWorld(GetGlobalWorld());}
- inline void CloseGlobalWorld(GlobalWorld oldWorld) {SetCurrentGlobalWorld(oldWorld);}
- #else
- #define GetGlobalWorld() (((void**)__gLibraryManager)[4])
- #define OpenGlobalWorld() SetCurrentGlobalWorld(GetGlobalWorld())
- #define CloseGlobalWorld(world) SetCurrentGlobalWorld(world)
- #endif
-
- OSErr InitGlobalWorld(); // called by standalone code only!!!
- void FreeGlobalWorld(); // called by standalone code only!!!
-
- #ifdef __cplusplus
- GlobalWorld SetCurrentGlobalWorld(GlobalWorld newWorld);
- GlobalWorld GetCurrentGlobalWorld();
-
- GlobalWorld GetGlobalWorld();
- GlobalWorld OpenGlobalWorld();
- void CloseGlobalWorld(GlobalWorld oldWorld);
- #endif
-
- /**********************************************************************
- ** TLibraryFile "C" interface
- **
- ** The C interface to the TLibraryFile class defined in
- ** LibraryManagerClasses.h. Used mainly to get resources out of a library.
- ***********************************************************************/
-
- #ifdef __cplusplus
- extern "C" {
- class TLibraryFile;
- #else
- typedef void TLibraryFile;
- #endif
-
- TLibraryFile* GetLocalLibraryFile();
-
- OSErr Preflight(TLibraryFile*, short* savedRefNum);
- OSErr Postflight(TLibraryFile*, short savedRefNum);
-
- Handle GetSharedResource(TLibraryFile*, ResType theType, short theID);
- Handle GetSharedIndResource(TLibraryFile*, ResType theType, short index);
- Handle GetSharedNamedResource(TLibraryFile*, ResType theType, ConstStr255Param name);
-
- void ReleaseSharedResource(TLibraryFile*, Handle);
- long CountSharedResources(TLibraryFile*, ResType theType);
-
- size_t GetSharedResourceUseCount(TLibraryFile*, Handle);
-
- long GetFileID(TLibraryFile*);
- long GetRefNum(TLibraryFile*);
- short GetVolumeRefNum(TLibraryFile*);
- OSErr CloseLibrary(TLibraryFile*);
-
- #ifdef __cplusplus
- }
- #endif
-
- /*******************************************************************************
- ** Debugging Macros and inlines
- ********************************************************************************/
-
- void DebugBreakProc(Boolean, const char*);
-
- #ifdef __cplusplus
- };
-
- inline void DoDebugBreak(Boolean value, const char* str)
- {
- DebugBreakProc(value, str);
- }
-
- inline void DoDebugBreak(const char* str)
- {
- DebugBreakProc(true, str);
- }
-
- #define ForceDebugBreak(str) DoDebugBreak(true, str)
-
- #if qDebug
- #define DebugBreak(str) DoDebugBreak(true, str)
- #define DebugTest(val, str) DoDebugBreak(val, str)
- #else
- #define DebugBreak(str)
- #define DebugTest(val, str)
- #endif
-
- #else
-
- #if qDebug
- #define DebugBreak(str) DebugBreakProc(true, str)
- #define DebugTest(val, str) DebugBreakProc(val, str)
- #else
- #define DebugBreak(str)
- #define DebugTest(val, str)
- #endif
-
- #endif __cplusplus
-
-
- #endif